Program Alone_Lumberjacking;
  {脱机伐木脚本，Alone于2022.08.17
   运行要求：
   1、魔法或者圣骑技能能够100%飞成功，穿100省药装备，快施2，快回4以上
   2、斧子拿在手上，如果使用魔法技能飞行，斧子必须有通道属性
   3、刻满伐木点的飞书5本
   4、刻2颗不同点的符石，要能从木头箱中拿取东西，然后放在同一本飞书中紧挨着的位置
   5、***务必***先使用辅助脚本生成一个记录所有飞点坐标的文件，并修改本脚本中的伐木点文件名后再运行}
   
//以下所有参数必须根据自身实际情况进行修改------------------------------------------
const
  BaoJingSheng = True;  //是否声音报警的开关变量，报警填True，不报警填False;
  ShengYinWenJian = 'D:\Program Files (x86)\Stealth\alarma.wav';  //此处引号中填写*完整*的报警声音文件名和路径
  ZhaoWeiBing = True;  //是否喊Guard的开关变量，喊的话填True，不喊填False(不在城区砍树不要喊);
  //
  FeiXingJiNeng = 5;  //此处填写飞行的技能代码，魔法为5，圣骑为7
  MuTouXiang = $44D91505;  //此处填写木头箱ID
  MuTouXiang_X = 2130;   //此处填写木头箱的X坐标
  MuTouXiang_Y = 875;  //此处填写木头箱的Y坐标
  DiYiBenFaMuShu = $436F83C1;  //此处填写第一本伐木点飞书的ID
  DiErBenFaMuShu = $436F7A1E;  //此处填写第二本伐木点飞书的ID
  DiSanBenFaMuShu = $436F6972; //此处填写第三本伐木点飞书的ID
  DiSiBenFaMuShu = $45791E1E;  //此处填写第四本伐木点飞书的ID
  DiWuBenFaMuShu = $4578FF88;  //此处填写第五本伐木点飞书的ID
  FeiHuiShu = $41B6A739;  //此处填写回家的飞书的ID
  DiYiHuiJiaDian = 1;  //此处填写飞回家的第一颗符石在回家的飞书中的位置（1~16）
  FaMuFangXiang = 1; //此处填写伐木时的朝向,0为N，1为E，2为S，3为W
  //
  CunPanShiJian = 200; //系统存盘时间，单位为0.1秒，要比实际存盘时间略长一点
//----------------------------------------------------------------------------------

Type
  ZuoBiaoDian = record X_ZuoBiao : Word;Y_ZuoBiao : Word;end;
var
  GMName : array of String;ShuTuXing : array of Word;ZuoBiaoJi : array of ZuoBiaoDian;
  FuChanPinTuXing, SouSuoJieGuo,FaMuShu  : array of Cardinal;QuTuXing : TStaticCell;
  DangQianShu, ShuX, ShuY, nowX, nowY, LinShi_X_ZuoBiao, LinShi_Y_ZuoBiao, JiShiZuoBiaoX,
  JiShiZuoBiaoY, ZuiDaFuZhong, DangQianFuZhong, PiYuZhi, HuiYuZhi : Word;
  ShuZ : ShortInt;TongJiShiChang : Single;XianShi, XPianYi, YPianYi : Integer;
  waiMS, waiMS2, WeiBingShiJian, TaoPao, PaoBuShu, FuShi, h, i, j, k, l, m,n : Byte;
  BaoJingShiChang, MuBanShu, MuBanZongJiShu, QiDongShiJian, ZongShiChang, ShengYuShiChang,
  TianShu, XiaoShiSHu, FenZhongShu, MiaoZhongShu : Cardinal;YunXingShiChang : String;
  TaoGuo, BaoGao, JianCeZuoBiao, ZuoBiaoYiChang : Boolean;
  
//下边一行引号中填写本伐木工对应的伐木点文件名，与脚本不在同一目录时须附带路径
{$Include 'FaMuDian_Fmu.txt'}
  
//GM列表，用于问话检测，可根据实际进行增减，注意总数要随之变动
procedure _GMLieBiao();
begin
setlength(GMName,9);
GMName[0] := 'Dysis';GMName[1] := 'Astraeus';GMName[2] := 'Marshall';
GMName[3] := 'Samael';GMName[4] := 'Asteria';GMName[5] := 'Tetra';
GMName[6] := 'Selene';GMName[7] := 'Eos';GMName[8] := 'Larson';
end;
  
procedure _HanWeiBing();begin WeiBingShiJian := WeiBingShiJian + 1;
if ( WeiBingShiJian = 2 ) then begin WeiBingShiJian := 0;UOsay('Guard');
end;end;procedure _TaoZhaDan();begin TaoPao := Random(8);for PaoBuShu := 0 to 4 do
begin if Step(TaoPao,True) <> 7 then begin TaoPao := TaoPao + 1;if (TaoPao = 8) then
TaoPao := 0;Step(TaoPao,True);end;end;end;procedure _FangZhaDan();begin if ( HP < MaxHP )
then begin if TaoGuo then begin TaoGuo := False;_TaoZhaDan;if FeiXingJiNeng = 5 then
begin CancelWaitTarget;CancelTarget;Cast('Greater Heal');WaitForTarget(4000);
TargetToObject(self);Wait(2400);end else if FeiXingJiNeng = 7 then begin CancelWaitTarget;
CancelTarget;Cast('Close Wounds');WaitForTarget(4000);TargetToObject(self);Wait(2400);
end;end;end;end;procedure _DuiHuaKuangJianCe(Serial,GumpID:Cardinal; X,Y:Integer);begin
if (GumpID = 3279111667) then begin for l := 0 to (GetGumpsCount-1) do begin
if ( GetGumpID(l) = 3279111667 ) then begin AddToSystemJournal('刷验证码了！！！');Break;
end;end;AddToSystemJournal('快看验证码');if BaoJingSheng then begin if
( timer - BaoJingShiChang ) >= 8000 then begin BaoJingShiChang := timer;PlayWav(ShengYinWenJian);
end;end;end;end;procedure _CunPanJianCe();begin if (InJournal('System: The world is saving') > -1)
then begin AddToSystemJournal('脚本暂停，等候系统存盘完成');XianShi := 0;while
InJournal('System: World save complete') = -1 do begin Wait(100);XianShi := XianShi + 1;
if XianShi >= CunPanShiJian then Break;end;ClearJournal;end else if
(InJournal('System: The world will save') > -1) then begin
AddToSystemJournal('系统即将存盘，等候存盘完成');XianShi := -100;
while InJournal('System: World save complete') = -1 do begin Wait(100);XianShi := XianShi + 1;
if XianShi >= CunPanShiJian then Break;end;ClearJournal;end;end;procedure _DuanXianJianCe();
begin if not Connected then begin Connect;waiMS := 0;repeat Wait(500);waiMS := waiMS + 1;
AddToSystemJournal('掉线了，重连中...');if waiMS >= 10 then begin Connect;waiMS := 0;end;
until Connected;end;end;function _Du_X_ZuoBiao():Word;begin LinShi_X_ZuoBiao := 0;repeat
_DuanXianJianCe;LinShi_X_ZuoBiao := GetX(self);until LinShi_X_ZuoBiao <> 0;
Result := LinShi_X_ZuoBiao;end;function _Du_Y_ZuoBiao():Word;begin LinShi_Y_ZuoBiao := 0;
repeat _DuanXianJianCe;LinShi_Y_ZuoBiao := GetY(self);until LinShi_Y_ZuoBiao <> 0;
Result := LinShi_Y_ZuoBiao;end;procedure _yiwai();begin _DuanXianJianCe;while Dead do
begin AddToSystemJournal('伐木工已死亡，请赶紧查看！！！');Wait(2000);end;
if JianCeZuoBiao then begin JiShiZuoBiaoX := _Du_X_ZuoBiao;
JiShiZuoBiaoY := _Du_Y_ZuoBiao;ZuoBiaoYiChang := True;
if ( Dist( JiShiZuoBiaoX, JiShiZuoBiaoY, MuTouXiang_X, MuTouXiang_Y ) < 3 ) then
ZuoBiaoYiChang := False else begin h := ( (j - 1)*16 + k ) + 1;
for m := 1 to 80 do begin h := h - 1;if ( h = 0 ) then h := 80;
if ( Dist( JiShiZuoBiaoX, JiShiZuoBiaoY, ZuoBiaoJi[h].X_ZuoBiao, ZuoBiaoJi[h].Y_ZuoBiao ) < 10 )
then begin ZuoBiaoYiChang := False;Break;end;end;end;if ZuoBiaoYiChang then begin
AddToSystemJournal('坐标异常，可能被抓了，快看一下！！！');if BaoJingSheng then begin
if ( timer - BaoJingShiChang ) >= 8000 then begin BaoJingShiChang := timer;
PlayWav(ShengYinWenJian);end;end;Wait(2000);end;end;
if BaoJingSheng then begin if GetGumpsCount > 0 then begin
for h := 0 to (GetGumpsCount-1) do begin if GetGumpID(h) = 3279111667 then
begin if ( timer - BaoJingShiChang ) >= 8000 then begin
AddToSystemJournal('赶紧填写验证码！！！');BaoJingShiChang := timer;
PlayWav(ShengYinWenJian);end;Break;end;end;end;for n := 0 to Length(GMName) -1 do
begin if (FindType($03DB,Ground) > 0) or (InJournal(GMName[n] + ': ') > -1) then
begin if ( timer - BaoJingShiChang ) >= 8000 then  begin
AddToSystemJournal('GM巡查了，快看一下！！！');BaoJingShiChang := timer;
PlayWav(ShengYinWenJian);end;end;end;end;if ( timer - BaoJingShiChang ) >= 16000
then BaoJingShiChang := timer - 8000;end;  
procedure _BaoGao();begin ZongShiChang := timer - QiDongShiJian;
TianShu := Trunc(ZongShiChang / 86400000);
ShengYuShiChang := ZongShiChang - (TianShu * 86400000);
XiaoShiSHu := Trunc(ShengYuShiChang / 3600000);
ShengYuShiChang := ShengYuShiChang - (XiaoShiSHu * 3600000);
FenZhongShu := Trunc(ShengYuShiChang / 60000);
ShengYuShiChang := ShengYuShiChang - (FenZhongShu * 60000);
MiaoZhongShu := Trunc(ShengYuShiChang / 1000);YunXingShiChang := '脚本运行时长: ';
if TianShu > 0 then YunXingShiChang := YunXingShiChang + IntToStr(TianShu) + ' 天 ';
if XiaoShiSHu > 0 then YunXingShiChang := YunXingShiChang + IntToStr(XiaoShiSHu) + ' 小时 ';
if FenZhongShu > 0 then YunXingShiChang := YunXingShiChang + IntToStr(FenZhongShu) + ' 分 ';
if MiaoZhongShu > 0 then YunXingShiChang := YunXingShiChang + IntToStr(MiaoZhongShu) + ' 秒';
AddToSystemJournal(YunXingShiChang + '；');TongJiShiChang := ZongShiChang / 3600000 ;
if FindTypesArrayEx([$1BD7], [0, 2010, 1191, 1192, 1193, 1194, 1151], [backpack], false) > 0
then MuBanShu := MuBanZongJiShu + FindFullQuantity else MuBanShu := MuBanZongJiShu;
AddToSystemJournal('共砍到木头 ' + IntToStr(MuBanShu) + '，平均每小时 ' +
IntToStr(Round( MuBanShu / TongJiShiChang )) + '；');end;function _PiMuBan():Boolean;begin
Result := False;Setlength(SouSuoJieGuo, 0);FindType($1BDD, Backpack);CheckLag(400);
SouSuoJieGuo := GetFoundItems;if Length(SouSuoJieGuo) > 0 then begin
for i := 0 to Length(SouSuoJieGuo) -1 do begin CancelTarget;
UseObject(ObjAtLayer(LhandLayer));WaitForTarget(1000);TargetToObject(SouSuoJieGuo[i]);
AddToSystemJournal('劈木板中。。。');Wait(600);end;Result := True;
AddToSystemJournal('完成，当前负重 ' + IntToStr(Weight) + '/' + IntToStr(ZuiDaFuZhong));
end;end;function _FuZhong():Word;begin Result := 0;DangQianFuZhong := 0;repeat
_DuanXianJianCe;DangQianFuZhong := Weight;until DangQianFuZhong <> 0;Result := DangQianFuZhong;
end;procedure _FeiXing(FeiShu:Cardinal;FeiDian:Byte;HuanDian:Boolean);begin FuShi := FeiDian;
nowX := _Du_X_ZuoBiao;nowY := _Du_Y_ZuoBiao;ClearJournal;
while ( ( nowX = _Du_X_ZuoBiao ) and ( nowY = _Du_Y_ZuoBiao ) ) do begin
While IsGump and IsGumpCanBeClosed(GetGumpsCount-1) do begin CloseSimpleGump(GetGumpsCount-1);
_yiwai;end;UseObject(FeiShu);waiMS2 := 0;while GetGumpID(GetGumpsCount-1) <> 1431013363 do
begin Wait(100);waiMS2 := waiMS2 + 1;if waiMS2 >= 40 then begin _yiwai;_CunPanJianCe;
UseObject(FeiShu);waiMS2 := 0;end;end;while ( _FuZhong > ZuiDaFuZhong ) do _PiMuBan;
waiMS2 := 0;if GetGumpID(GetGumpsCount-1) = 1431013363 then begin
NumGumpButton( GetGumpsCount-1, (FeiXingJiNeng + (FuShi - 1)*6) );if HuanDian then begin if ( FuShi = FeiDian )
then FuShi := FuShi + 1 else FuShi := FeiDian;end;repeat Wait(500);waiMS2 := waiMS2 + 1;
until ( nowX <> _Du_X_ZuoBiao ) or ( nowY <> _Du_Y_ZuoBiao ) or ( InJournal('blocked') > -1 ) or ( waiMS2 >= 8 );
if ( InJournal('blocked') > -1 ) then begin ClearJournal;if not HuanDian then Break;end;end;_yiwai;end;end;
procedure _FangChengGuo();begin if FindTypesArrayEx([$1BD7], [0, 2010, 1191, 1192, 1193, 1194, 1151], [backpack], false) > 0
then begin AddToSystemJournal('放木板中。。。');MuBanZongJiShu := MuBanZongJiShu +
FindFullQuantity;MoveItems(backpack, $1BD7, -1, MuTouXiang, 0,0,0, 600);CheckLag(6000);end;
for i := 0 to Length(FuChanPinTuXing) -1 do begin
if FindType(FuChanPinTuXing[i], backpack) > 0 then begin
AddToSystemJournal('放副产品中。。。');MoveItems(backpack, FuChanPinTuXing[i], -1,
MuTouXiang, 0,0,0, 600);CheckLag(1200);end;end;end;begin _DuQuZuoBiaoWenJian;JianCeZuoBiao := False;
Setlength(ShuTuXing,45);ShuTuXing[0]:=3240;
ShuTuXing[1]:=3242;ShuTuXing[2]:=3277;ShuTuXing[3]:=3278;ShuTuXing[4]:=3280;
ShuTuXing[5]:=3281;ShuTuXing[6]:=3283;ShuTuXing[7]:=3284;ShuTuXing[8]:=3286;
ShuTuXing[9]:=3287;ShuTuXing[10]:=3288;ShuTuXing[11]:=3289;ShuTuXing[12]:=3290;
ShuTuXing[13]:=3291;ShuTuXing[14]:=3293;ShuTuXing[15]:=3294;ShuTuXing[16]:=3296;
ShuTuXing[17]:=3297;ShuTuXing[18]:=3299;ShuTuXing[19]:=3300;ShuTuXing[20]:=3302;
ShuTuXing[21]:=3393;ShuTuXing[22]:=3394;ShuTuXing[23]:=3395;ShuTuXing[24]:=3396;
ShuTuXing[25]:=3408;ShuTuXing[26]:=3415;ShuTuXing[27]:=3416;ShuTuXing[28]:=3417;
ShuTuXing[29]:=3418;ShuTuXing[30]:=3419;ShuTuXing[31]:=3438;ShuTuXing[32]:=3439;
ShuTuXing[33]:=3440;ShuTuXing[34]:=3441;ShuTuXing[35]:=3442;ShuTuXing[36]:=3446;
ShuTuXing[37]:=3460;ShuTuXing[38]:=3461;ShuTuXing[39]:=3462;ShuTuXing[40]:=3465;
ShuTuXing[41]:=3470;ShuTuXing[42]:=3480;ShuTuXing[43]:=3482;ShuTuXing[44]:=3488;
Setlength(FuChanPinTuXing,5);FuChanPinTuXing[0] := $318F;FuChanPinTuXing[1] := $3190;
FuChanPinTuXing[2] := $3191;FuChanPinTuXing[3] := $3199;FuChanPinTuXing[4] := $2F5F;
Setlength(FaMuShu,5);FaMuShu[0] := DiYiBenFaMuShu;FaMuShu[1] := DiErBenFaMuShu;
FaMuShu[2] := DiSanBenFaMuShu;FaMuShu[3] := DiSiBenFaMuShu;FaMuShu[4] := DiWuBenFaMuShu;
_GMLieBiao;case FaMuFangXiang of 0 : begin XPianYi := 0;YPianYi := -1;end;
1 : begin XPianYi := 1;YPianYi := 0;end;2 : begin XPianYi := 0;YPianYi := 1;end;
3 : begin XPianYi := -1;YPianYi := 0;end;end;MuBanZongJiShu := 0;
if not Connected then begin Connect;waiMS := 0;repeat Wait(500);waiMS := waiMS + 1;
AddToSystemJournal('ID不在线，登录中...');if waiMS >= 10 then begin
if InJournal('reason : Another character from this account') > -1 then begin
AddToSystemJournal('当前账号下的其他ID在线，无法登录，脚本终止');Halt;
end;Connect;waiMS := 0;end;until Connected;end;BaoJingShiChang := timer - 8000;
QiDongShiJian := timer;AddToSystemJournal('欢迎使用alone脱机伐木脚本，版本2022.08.17');
repeat ZuiDaFuZhong := MaxWeight;Wait(50);until ZuiDaFuZhong > 0;
if ( Dist( _Du_X_ZuoBiao, _Du_Y_ZuoBiao, MuTouXiang_X, MuTouXiang_Y ) > 2 ) then begin
AddToSystemJournal('先飞到木头箱前');_FeiXing(FeiHuiShu, DiYiHuiJiaDian, True);end;
if ZuiDaFuZhong > 550 then PiYuZhi := 484 else PiYuZhi := ZuiDaFuZhong - 66;
HuiYuZhi := PiYuZhi + 22;if ZhaoWeiBing then begin WeiBingShiJian := 0;
SetEventProc(evTimer1, '_HanWeiBing');end;SetEventProc(evTimer2, '_FangZhaDan');
SetEventProc(evIncomingGump, '_DuiHuaKuangJianCe');JianCeZuoBiao := True;
for j := 1 to 5 do begin for k := 1 to 16 do
begin if ( Dist( _Du_X_ZuoBiao, _Du_Y_ZuoBiao, MuTouXiang_X, MuTouXiang_Y ) < 3 )
then begin _FangChengGuo;_BaoGao;end;AddToSystemJournal('飞往下一个伐木点。。。');
_FeiXing(FaMuShu[j - 1], k, False);ClearJournal;TaoGuo := True;
if ( Dist( _Du_X_ZuoBiao, _Du_Y_ZuoBiao, MuTouXiang_X, MuTouXiang_Y ) > 2 ) then begin
AddToSystemJournal('正在第 ' + IntToStr(j) + ' 本书的第 ' + IntToStr(k) + ' 个点努力砍树');
DangQianShu := 0;ShuX := GetX(self) + XPianYi;ShuY := GetY(self) + YPianYi;
QuTuXing := ReadStaticsXY(ShuX, ShuY, WorldNum);if Length(QuTuXing.Statics) > 0 then begin
for i := 0 to Length(ShuTuXing) -1 do begin if ShuTuXing[i] = QuTuXing.Statics[0].Tile then
begin DangQianShu := QuTuXing.Statics[0].Tile;ShuZ := QuTuXing.Statics[0].Z;Break;end;end;end;
if DangQianShu > 0 then begin repeat _yiwai;CancelTarget;UseObject(ObjAtLayer(LhandLayer));
WaitTargetTile(DangQianShu, ShuX, ShuY, ShuZ);Wait(550);if ( FindType($0F0D, Ground) > 0 )
then _TaoZhaDan;if ( Weight >= PiYuZhi ) then begin BaoGao := _PiMuBan;if ( Weight >= HuiYuZhi )
then begin repeat AddToSystemJournal('飞回木头箱前。。。');_FeiXing(FeiHuiShu, DiYiHuiJiaDian, True);
until ( Dist( _Du_X_ZuoBiao, _Du_Y_ZuoBiao, MuTouXiang_X, MuTouXiang_Y ) < 3 );Break;end else
if BaoGao then AddToSystemJournal('继续砍第 ' + IntToStr(j) + ' 本书的第 ' + IntToStr(k) +
' 个点。。。');end;until ( (InJournal('enough') > -1) or (InJournal('axe') > -1)
or (InJournal('too far') > -1) );end;end;end;if ( j = 5 ) then j := 0;end;end.